package com.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/login")
public class loginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1 如何接收数据
        String uName = req.getParameter("username");
        String passwordP = req.getParameter("password");

        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        if (uName != null && uName.length()>0 && passwordP != null && passwordP.length()>0) {
            //验证
            if (uName.equals("abc") && passwordP.equals("123")) {
                out.println(uName + ":欢迎你");
            }else {
                out.println("用户名或者密码不正确");
            }
        } else {
            out.println("用户名或者密码为空");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
